package com.shopowner.controller;

import com.shopowner.dto.DTO;
import com.shopowner.page.PageInfo;
import com.shopowner.entity.Shopowner;
import com.shopowner.service.ShopownerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@CrossOrigin
@Controller
@RequestMapping("/shopownerController")
public class ShopownerController {
	@Resource
	ShopownerService shopownerService;
	@RequestMapping("/getAllShopowner")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<Shopowner> getAllShopowner() throws Exception {
    	System.out.println("查询全部店长");
		return shopownerService.getAllShopowners();
    }
	@RequestMapping("/selectShopownerBySno/{sno}")
	@ResponseBody
	public DTO<Shopowner> selectShopownerBySno(@PathVariable("sno") String sno) throws Exception {
		System.out.println("根据主键查询");
		return shopownerService.selectShopownerBySno(sno);
	}
	@RequestMapping("/deleteShopownerBySno/{sno}")
	@ResponseBody
    public DTO<Shopowner> deleteShopownerBySno(@PathVariable("sno") String sno) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(sno+"删除店长");
    	return shopownerService.deleteShopownerBySno(sno);
    }

	@RequestMapping("/updateShopownerBySno")
	@ResponseBody
	public DTO<Shopowner> updateShopownerBySno(@RequestBody Shopowner shopowner) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("修改店长");
		return shopownerService.updateShopownerBySno(shopowner);
	}


	@RequestMapping("/addShopowner")
	@ResponseBody
	public DTO<Shopowner> addShopowner(@RequestBody Shopowner shopowner) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加店长");
		System.out.println(shopowner);
 		return shopownerService.addShopowner(shopowner);
	}

	@RequestMapping("/getShopownerByPage")
	@ResponseBody
	public DTO<Shopowner> getShopownerByPage(PageInfo pageInfo) throws Exception{//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("分页店长");
		return shopownerService.getShopownerByPage(pageInfo);
	}


}